package cn.wolfcode.wolf2w.job.task;

import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component("messageJob")
public class MessageJob {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void esDataJob(){
        String key = RedisKeys.ES_DATA.join("key");
        long max = System.currentTimeMillis() - 5 * 60 * 1000;
        Set<String> messages = stringRedisTemplate.opsForZSet().rangeByScore(key, 0, max);
        for (String message : messages) {
            //重发消息
            amqpTemplate.convertAndSend("esTopicExchange","esKey",message);
        }

    }

}
